#include "vertex.h"
#include "vector.h"
#include "edge.h"
#include "face.h"

Vertex::Vertex(int _id, const Vector3D &_pos, const Color &_c, HalfEdge *_he) : id(_id), selected(false), color(_c), position(_pos), he(_he){
}

void Vertex::translate(const Vector3D &_t)
{
    position = position + _t;
}

void Vertex::rotate(const Matrix &_m)
{
    position = (_m * position.toHomogeneousCoordinates()).fromHomogeneousCoordinates();
}

void Vertex::scale(const Matrix &_m)
{
    position = (_m * position.toHomogeneousCoordinates()).fromHomogeneousCoordinates();
}

void Vertex::selectAdjacentVertex()
{
    HalfEdge *scan = he;
    do{
        Vertex *v = scan->getTwin()->getVertex();
        v->select(true);

        scan = scan->getTwin()->getNext();
    }while( scan != he );
}

void Vertex::selectAdjacentEdge()
{
    HalfEdge *scan = he;
    do{
        Edge *e = scan->getEdge();
        e->select(true);

        scan = scan->getTwin()->getNext();
    }while( scan != he );

    selected = false;
}

void Vertex::selectAdjacentFace()
{
    HalfEdge *scan = he;
    do{
        Face *f = scan->getLoop()->getFace();
        f->select(true);

        scan = scan->getTwin()->getNext();
    }while( scan != he );

    selected = false;
}
